package com.language.points.multi.thread.zhishu;

import java.util.List;
import java.util.Vector;

/**
 * 多线程 - 查找质数基类
 * @author yll
 * @version 1.0.0
 * @date 2024/04/14 14：25
 * @desc 基类
 * */
public  class BaseFindZhiShu {
    public BaseFindZhiShu(){
        System.out.println("BaseFindZhiShu");
    }
    public List<Integer> zhishuList = new Vector<Integer>();

    public boolean checkZhiShu(Integer num){
        boolean is_this = true;
        if(num < 2){
            is_this = false;
        }else if(num > 2){
            for (int i = 2; i < num; i++){
                if(num % i == 0){
                    is_this = false;
                    break;
                }
            }
        }
        return is_this;
    }
    public void findZhiShu(Integer startNum, Integer endNum){
        for (int i = startNum; i <= endNum; i++){
            if(checkZhiShu(i)){
                zhishuList.add(i);
            }
        }
    }

//    public synchronized void addZhiShuList(List<Integer> tempList){
//        zhishuList.addAll(tempList);
//    }

    public void showZhiShu(){
        System.out.println("***********");
        System.out.println("共有个" + zhishuList.size() + "质数！");
        if(zhishuList != null && zhishuList.size() > 0) {
            for (Integer num : zhishuList) {
                System.out.print(num + "\t");
            }
        }
        zhishuList.clear();
        System.out.println("***********");
        System.out.println("");
    }
}
